package com.beiding.jsonanalyzer.analyze.query;

import com.beiding.jsonanalyzer.analyze.func.FuncBase;
import com.beiding.jsonanalyzer.flow.ValueNode;

/**
 * 子条件
 */
public class NotCondition implements FuncBase<ComparatorResult> {

    private FuncBase<ComparatorResult> core;

    public NotCondition(FuncBase<ComparatorResult> core) {
        this.core = core;
    }

    @Override
    public boolean checkAgg() {
        return core.checkAgg();
    }

    @Override
    public ComparatorResult executeOne(ValueNode valueNode) {

        //执行单个结果
        ComparatorResult compareResult = core.executeOne(valueNode);

        //返回逆向结果
        if (compareResult == ComparatorResult.TRUE) {
            return ComparatorResult.FALSE;
        } else if (compareResult == ComparatorResult.FALSE) {
            return ComparatorResult.TRUE;
        }
        return null;
    }

    @Override
    public void pugAgg(ValueNode valueNode) {
        core.pugAgg(valueNode);
    }

    @Override
    public void resetAgg() {
        core.resetAgg();
    }

    @Override
    public ComparatorResult aggGet() {
        ComparatorResult compareResult = core.aggGet();

        //返回逆向结果
        if (compareResult == ComparatorResult.TRUE) {
            return ComparatorResult.FALSE;
        } else if (compareResult == ComparatorResult.FALSE) {
            return ComparatorResult.TRUE;
        }
        return null;
    }

    @Override
    public String toString() {
        return "not " +
                core;
    }
}
